package com.ruoyi.bak.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bak.domain.BakOperatorRecord;
import com.ruoyi.bak.service.IBakOperatorRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 操作记录Controller
 * 
 * @author ruoyi
 * @date 2023-02-12
 */
@Controller
@RequestMapping("/bak/record")
public class BakOperatorRecordController extends BaseController
{
    private String prefix = "bak/record";

    @Autowired
    private IBakOperatorRecordService bakOperatorRecordService;

    @RequiresPermissions("bak:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询操作记录列表
     */
    @RequiresPermissions("bak:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BakOperatorRecord bakOperatorRecord)
    {
        startPage();
        List<BakOperatorRecord> list = bakOperatorRecordService.selectBakOperatorRecordList(bakOperatorRecord);
        return getDataTable(list);
    }

    /**
     * 导出操作记录列表
     */
    @RequiresPermissions("bak:record:export")
    @Log(title = "操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BakOperatorRecord bakOperatorRecord)
    {
        List<BakOperatorRecord> list = bakOperatorRecordService.selectBakOperatorRecordList(bakOperatorRecord);
        ExcelUtil<BakOperatorRecord> util = new ExcelUtil<BakOperatorRecord>(BakOperatorRecord.class);
        return util.exportExcel(list, "操作记录数据");
    }

    /**
     * 新增操作记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存操作记录
     */
    @RequiresPermissions("bak:record:add")
    @Log(title = "操作记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BakOperatorRecord bakOperatorRecord)
    {
        return toAjax(bakOperatorRecordService.insertBakOperatorRecord(bakOperatorRecord));
    }

    /**
     * 修改操作记录
     */
    @RequiresPermissions("bak:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BakOperatorRecord bakOperatorRecord = bakOperatorRecordService.selectBakOperatorRecordById(id);
        mmap.put("bakOperatorRecord", bakOperatorRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存操作记录
     */
    @RequiresPermissions("bak:record:edit")
    @Log(title = "操作记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BakOperatorRecord bakOperatorRecord)
    {
        return toAjax(bakOperatorRecordService.updateBakOperatorRecord(bakOperatorRecord));
    }

    /**
     * 删除操作记录
     */
    @RequiresPermissions("bak:record:remove")
    @Log(title = "操作记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bakOperatorRecordService.deleteBakOperatorRecordByIds(ids));
    }
}
